﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Clothes.Model;
using Clothes.IDAL;

namespace Clothes.DAL
{
    public class CLDressDAL:BaseDAL<CLDress>,CLDressIDAL
    {
        /// <summary>
        /// 根据Id进行降序排序
        /// </summary>
        /// <returns></returns>
        public List<CLDress> SelctOrderBy()
        {
            return context.CLDress.OrderByDescending(a => a.Id).ToList();
        }

        public bool Edit(int id, int shu)
        {
            using (ClothesContext db = new ClothesContext())
            {
                var e = db.CLDress.FirstOrDefault(a => a.Id == id);
                int a1 = Convert.ToInt32(e.Surplus);
                int a3 =Convert.ToInt32(e.Number) +shu;
                if (a1 > a3) {
                    int a2 = a1 - a3;
                    e.Number = a3;
                    e.Sur = a2;
                    return db.SaveChanges() > 0;
                }
                if (a1 < a3) {
                    return false;
                }
                return false;
            }
        }
    }
}
